export default class Watcher {
  constructor (vm, expOrFn, cb) {
    this.vm = vm
    this.getter = parasePath(expOrFn)
    this.cb = cb
    this.value = this.get()
  }
  get () {
    // 先把全局的global.target设置成watcher实例
    global.target = this
    let value = this.getter.call(this.vm, this.vm)
    global.target = undefined
    return value
  }
  update () {
    const oldValue = this.value
    this.value = this.get()
    this.cb.call(this.vm, this.value, this.oldValue)
  }
}